package com.tk.array;

public class Demo01 {
    public static void main(String[] args) {
        int[] arrays = {1, 2, 3, 4};
        //打印数组元素
        for (int i = 0; i < arrays.length; i++) {
            System.out.println(arrays[i]);
        }
        System.out.println("---------");
        //遍历数组元素
        for (int array : arrays) {
            System.out.println(array);
        }

        //求和
        int sum = 0;
        for (int i = 0; i < arrays.length; i++) {
            sum += arrays[i];
        }
        System.out.println("sum=" + sum); //sum=10

        //最大值
        int max = arrays[0];
        for (int i = 1; i < arrays.length; i++) {
            if (arrays[i] > max) {
                max = arrays[i];
            }
        }
        System.out.println("max=" + max); //max=4
    }
}
